#include "Enemy.h"
#include "ManageGame.h"
#include "SteeringBehaviors.h"


/***********************************************\
|				CONSTRUCTOR						| 
\***********************************************/
Enemy::Enemy()
{

}
Enemy::Enemy(Enemy* E)
{

}
Enemy::Enemy(point loc, int assetindex) : BaseObject(loc, assetindex)
{
	m_pStateMachine = new StateMachine<Enemy>(this);
	m_pSteering = new SteeringBehaviors();
	/*                     TODO                      */
	//m_pStateMachine->SetCurrentState(Meditate::Instance());     SET STARTING STATE
	//m_pStateMachine->SetGlobalState(ImmortalGlobalState::Instance());    GLOBAL STATE
}

/***********************************************\
|				DESTRUCTOR						| 
\***********************************************/
Enemy::~Enemy()
{
	if(m_pStateMachine != NULL)
	{
		delete m_pStateMachine; 
		m_pStateMachine = NULL;
	}
	if(m_pSteering != NULL)
	{
		delete m_pSteering;
		m_pSteering = NULL;
	}
}

/** @param a_ms the number of milliseconds passed since the last time update was called */
void Enemy::update(int a_ms)
{
	point totalMove;
	totalMove.x = m_Velocity.x*a_ms/1000;
	totalMove.y = m_Velocity.y*a_ms/1000;

	m_location.x += totalMove.x;
	m_location.y += totalMove.y;
	m_pStateMachine->Update();
}

void Enemy::collideWith(BaseObject * obj)
{
	int index = g_app.getMap()->getMobs()->indexOf(obj);
	g_app.getMap()->getMobs()->remove(index);
	void * toDie = g_app.getGraphics()->RemoveObject(obj, 0);
	g_app.addEvent(QueuedEvent::DELETE_BASE_OBJ, obj);
}

//bool Immortal::HandleMessage(const Telegram& msg)
//{
//  return f_pStateMachine->HandleMessage(msg);
//}

//void Immortal::SetE(double e)
//{
//	if(e == 0) 
//		whoisenemy = ent_Immortal; 
//	else if(e == 1)
//		whoisenemy = ent_Immortal2;
//	else if(e == 2)
//		whoisenemy = ent_Immortal3;
//	else if(e == 3)
//		whoisenemy = ent_Immortal4;
//}		